//
//  CGGeometry+MKExtension.h
//  MKUI
//
//  Created by sushangjin on 2018/12/16.
//  Copyright © 2018 sushangjin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef enum : NSUInteger {
	MKCGAxisX,//X轴
	MKCGAxisY,//Y轴
} MKCGAxis;
UIKIT_STATIC_INLINE MKCGAxis MKCGAxisReverse(MKCGAxis axis){
	return axis==MKCGAxisX?MKCGAxisY:MKCGAxisX;
}
#pragma mark - CGPoint
UIKIT_STATIC_INLINE CGFloat MKCGPointGetValue(CGPoint point,MKCGAxis axis){
	return axis==MKCGAxisX?point.x:point.y;
}
UIKIT_STATIC_INLINE void MKCGPointSetValue(CGPoint *point,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){(*point).x=value;}else{(*point).y=value;}
}
UIKIT_STATIC_INLINE void MKCGPointAddValue(CGPoint *point,MKCGAxis axis,CGFloat value){
    MKCGPointSetValue(point, axis, MKCGPointGetValue(*point, axis)+value);
}

#pragma mark - CGVector
UIKIT_STATIC_INLINE CGFloat MKCGVectorGetValue(CGVector v,MKCGAxis axis){
	return axis==MKCGAxisX?v.dx:v.dy;
}
UIKIT_STATIC_INLINE void MKCGVectorSetValue(CGVector *v,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){(*v).dx=value;}else{(*v).dy=value;}
}
UIKIT_STATIC_INLINE void MKCGVectorAddValue(CGVector *v,MKCGAxis axis,CGFloat value){
    MKCGVectorSetValue(v, axis, MKCGVectorGetValue(*v, axis)+value);
}

#pragma mark - CGSize
UIKIT_STATIC_INLINE CGFloat MKCGSizeGetLength(CGSize size,MKCGAxis axis){
	return axis==MKCGAxisX?size.width:size.height;
}
UIKIT_STATIC_INLINE void MKCGSizeSetLength(CGSize *size,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){(*size).width=value;}else{(*size).height=value;}
}
UIKIT_STATIC_INLINE void MKCGSizeAddLength(CGSize *size,MKCGAxis axis,CGFloat value){
    MKCGSizeSetLength(size, axis, MKCGSizeGetLength(*size, axis)+value);
}

#pragma mark - CGRect
typedef enum : NSUInteger {
	MKCGRectAlignmentMin,//min最小值对齐
	MKCGRectAlignmentMid,//mid中值对齐
	MKCGRectAlignmentMax,//max最大值对齐
} MKCGRectAlignment;//对齐方向
UIKIT_STATIC_INLINE MKCGRectAlignment MKCGRectAlignmentReverse(MKCGRectAlignment align){
    return align==MKCGRectAlignmentMin?MKCGRectAlignmentMax:(align==MKCGRectAlignmentMax?MKCGRectAlignmentMin:MKCGRectAlignmentMid);
}

UIKIT_STATIC_INLINE void MKCGRectSetMinX(CGRect *rect,CGFloat value){
	(*rect).origin.x = value;
}
UIKIT_STATIC_INLINE void MKCGRectSetMinY(CGRect *rect,CGFloat value){
	(*rect).origin.y = value;
}
UIKIT_STATIC_INLINE void MKCGRectSetMidX(CGRect *rect,CGFloat value){
	(*rect).origin.x = value-(*rect).size.width*0.5;
}
UIKIT_STATIC_INLINE void MKCGRectSetMidY(CGRect *rect,CGFloat value){
	(*rect).origin.y = value-(*rect).size.height*0.5;
}
UIKIT_STATIC_INLINE void MKCGRectSetMaxX(CGRect *rect,CGFloat value){
	(*rect).origin.x = value-(*rect).size.width;
}
UIKIT_STATIC_INLINE void MKCGRectSetMaxY(CGRect *rect,CGFloat value){
	(*rect).origin.y = value-(*rect).size.height;
}
UIKIT_STATIC_INLINE void MKCGRectSetWidth(CGRect *rect,CGFloat value){
	(*rect).size.width = value;
}
UIKIT_STATIC_INLINE void MKCGRectSetHeight(CGRect *rect,CGFloat value){
	(*rect).size.height = value;
}
UIKIT_STATIC_INLINE CGPoint MKCGRectGetCenter(CGRect rect){
	return CGPointMake(CGRectGetMidX(rect),CGRectGetMidY(rect));
}
UIKIT_STATIC_INLINE void MKCGRectSetCenter(CGRect *rect,CGPoint center){
	MKCGRectSetMidX(rect, center.x);MKCGRectSetMidY(rect, center.y);
}
UIKIT_STATIC_INLINE CGFloat MKCGRectGetPercentX(CGRect rect,CGFloat percent){
	return CGRectGetMinX(rect)+percent*CGRectGetWidth(rect);
}
UIKIT_STATIC_INLINE CGFloat MKCGRectGetPercentY(CGRect rect,CGFloat percent){
	return CGRectGetMinY(rect)+percent*CGRectGetHeight(rect);
}
UIKIT_STATIC_INLINE void MKCGRectSetMinXEdgeToRect(CGRect *rect,CGRect bounds,CGFloat edge){
	MKCGRectSetMinX(rect, CGRectGetMinX(bounds)+edge);
}
UIKIT_STATIC_INLINE void MKCGRectSetMaxXEdgeToRect(CGRect *rect,CGRect bounds,CGFloat edge){
	MKCGRectSetMaxX(rect, CGRectGetMaxX(bounds)-edge);
}
UIKIT_STATIC_INLINE void MKCGRectSetMinYEdgeToRect(CGRect *rect,CGRect bounds,CGFloat edge){
	MKCGRectSetMinY(rect, CGRectGetMinY(bounds)+edge);
}
UIKIT_STATIC_INLINE void MKCGRectSetMaxYEdgeToRect(CGRect *rect,CGRect bounds,CGFloat edge){
	MKCGRectSetMaxY(rect, CGRectGetMaxY(bounds)-edge);
}

#pragma mark - 与另一个rect进行对齐
UIKIT_STATIC_INLINE void MKCGRectAlignCenterToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetCenter(rect, MKCGRectGetCenter(bounds));
}
UIKIT_STATIC_INLINE void MKCGRectAlignMinXToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetMinX(rect, CGRectGetMinX(bounds));
}
UIKIT_STATIC_INLINE void MKCGRectAlignMidXToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetMidX(rect, CGRectGetMidX(bounds));
}
UIKIT_STATIC_INLINE void MKCGRectAlignMaxXToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetMaxX(rect, CGRectGetMaxX(bounds));
}
UIKIT_STATIC_INLINE void MKCGRectAlignMinYToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetMinY(rect, CGRectGetMinY(bounds));
}
UIKIT_STATIC_INLINE void MKCGRectAlignMidYToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetMidY(rect, CGRectGetMidY(bounds));
}
UIKIT_STATIC_INLINE void MKCGRectAlignMaxYToRect(CGRect *rect,CGRect bounds){
	MKCGRectSetMaxY(rect, CGRectGetMaxY(bounds));
}

#pragma mark - Axis operation
UIKIT_STATIC_INLINE CGFloat MKCGRectGetMin(CGRect rect,MKCGAxis axis){
	return axis==MKCGAxisX?CGRectGetMinX(rect):CGRectGetMinY(rect);
}
UIKIT_STATIC_INLINE void MKCGRectSetMin(CGRect *rect,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){MKCGRectSetMinX(rect,value);}else{MKCGRectSetMinY(rect,value);}
}
UIKIT_STATIC_INLINE void MKCGRectAddMin(CGRect *rect,MKCGAxis axis,CGFloat value){
    MKCGRectSetMin(rect, axis, MKCGRectGetMin(*rect, axis)+value);
}
UIKIT_STATIC_INLINE CGFloat MKCGRectGetMid(CGRect rect,MKCGAxis axis){
	return axis==MKCGAxisX?CGRectGetMidX(rect):CGRectGetMidY(rect);
}
UIKIT_STATIC_INLINE void MKCGRectSetMid(CGRect *rect,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){MKCGRectSetMidX(rect,value);}else{MKCGRectSetMidY(rect,value);}
}
UIKIT_STATIC_INLINE void MKCGRectAddMid(CGRect *rect,MKCGAxis axis,CGFloat value){
    MKCGRectSetMid(rect, axis, MKCGRectGetMid(*rect, axis)+value);
}
UIKIT_STATIC_INLINE CGFloat MKCGRectGetMax(CGRect rect,MKCGAxis axis){
	return axis==MKCGAxisX?CGRectGetMaxX(rect):CGRectGetMaxY(rect);
}
UIKIT_STATIC_INLINE void MKCGRectSetMax(CGRect *rect,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){MKCGRectSetMaxX(rect,value);}else{MKCGRectSetMaxY(rect,value);}
}
UIKIT_STATIC_INLINE void MKCGRectAddMax(CGRect *rect,MKCGAxis axis,CGFloat value){
    MKCGRectSetMax(rect, axis, MKCGRectGetMax(*rect, axis)+value);
}
UIKIT_STATIC_INLINE void MKCGRectSetMinEdgeToRect(CGRect *rect,MKCGAxis axis,CGRect bounds,CGFloat edge){
	if(axis==MKCGAxisX){MKCGRectSetMinXEdgeToRect(rect, bounds, edge);}else{MKCGRectSetMinYEdgeToRect(rect, bounds, edge);}
}
UIKIT_STATIC_INLINE void MKCGRectSetMaxEdgeToRect(CGRect *rect,MKCGAxis axis,CGRect bounds,CGFloat edge){
	if(axis==MKCGAxisX){MKCGRectSetMaxXEdgeToRect(rect, bounds, edge);}else{MKCGRectSetMaxYEdgeToRect(rect, bounds, edge);}
}
UIKIT_STATIC_INLINE CGFloat MKCGRectGetLength(CGRect rect,MKCGAxis axis){
	return axis==MKCGAxisX?CGRectGetWidth(rect):CGRectGetHeight(rect);
}
UIKIT_STATIC_INLINE void MKCGRectSetLength(CGRect *rect,MKCGAxis axis,CGFloat value){
	if(axis==MKCGAxisX){MKCGRectSetWidth(rect,value);}else{MKCGRectSetHeight(rect,value);}
}
UIKIT_STATIC_INLINE void MKCGRectAddLength(CGRect *rect,MKCGAxis axis,CGFloat value){
    MKCGRectSetLength(rect, axis, MKCGRectGetLength(*rect, axis)+value);
}
UIKIT_STATIC_INLINE void MKCGRectAlignMinToRect(CGRect *rect,MKCGAxis axis,CGRect bounds){
	if(axis==MKCGAxisX){MKCGRectAlignMinXToRect(rect, bounds);}else{MKCGRectAlignMinYToRect(rect, bounds);}
}
UIKIT_STATIC_INLINE void MKCGRectAlignMidToRect(CGRect *rect,MKCGAxis axis,CGRect bounds){
	if(axis==MKCGAxisX){MKCGRectAlignMidXToRect(rect, bounds);}else{MKCGRectAlignMidYToRect(rect, bounds);}
}
UIKIT_STATIC_INLINE void MKCGRectAlignMaxToRect(CGRect *rect,MKCGAxis axis,CGRect bounds){
	if(axis==MKCGAxisX){MKCGRectAlignMaxXToRect(rect, bounds);}else{MKCGRectAlignMaxYToRect(rect, bounds);}
}
UIKIT_STATIC_INLINE void MKCGRectAlignToRect(CGRect *rect,MKCGAxis axis,MKCGRectAlignment alignment,CGRect bounds){
	switch (alignment) {
		case MKCGRectAlignmentMin:
			MKCGRectAlignMinToRect(rect,axis,bounds);
			break;
		case MKCGRectAlignmentMid:
			MKCGRectAlignMidToRect(rect,axis,bounds);
			break;
		case MKCGRectAlignmentMax:
			MKCGRectAlignMaxToRect(rect,axis,bounds);
			break;
	}
}
UIKIT_STATIC_INLINE void MKCGRectAlignMidCenterToRect(CGRect *rect,CGRect bounds){
    MKCGRectAlignMidToRect(rect, MKCGAxisX, bounds);
    MKCGRectAlignMidToRect(rect, MKCGAxisY, bounds);
}

#pragma mark - UIRectEdge

typedef enum : NSUInteger {
	MKUIEdgeInsetsMin,//对应于top,left
	MKUIEdgeInsetsMax,//对应于bottom,right
} MKUIEdgeInsetsEdge;

UIKIT_STATIC_INLINE CGFloat MKUIEdgeInsetsGetEdge(UIEdgeInsets insets,MKCGAxis axis,MKUIEdgeInsetsEdge edge){
	return axis==MKCGAxisX?(edge==MKUIEdgeInsetsMin?insets.left:insets.right):(edge==MKUIEdgeInsetsMin?insets.top:insets.bottom);
}
UIKIT_STATIC_INLINE CGFloat MKUIEdgeInsetsGetEdgeSum(UIEdgeInsets insets,MKCGAxis axis){
    return axis==MKCGAxisX?(insets.left+insets.right):(insets.top+insets.bottom);
}
UIKIT_STATIC_INLINE void MKUIEdgeInsetsSetEdge(UIEdgeInsets *insets,MKCGAxis axis,MKUIEdgeInsetsEdge edge,CGFloat value){
	if(axis==MKCGAxisX){if(edge==MKUIEdgeInsetsMin){(*insets).left=value;}else{(*insets).right=value;}}else{if(edge==MKUIEdgeInsetsMin){(*insets).top=value;}else{(*insets).bottom=value;}}
}
UIKIT_STATIC_INLINE void MKUIEdgeInsetsAddEdge(UIEdgeInsets *insets,MKCGAxis axis,MKUIEdgeInsetsEdge edge,CGFloat value){
    MKUIEdgeInsetsSetEdge(insets, axis, edge, MKUIEdgeInsetsGetEdge(*insets, axis, edge)+value);
}

#pragma mark - CGAffineTransform
UIKIT_STATIC_INLINE CGAffineTransform MKCGAffineTransformMakeTranslation(MKCGAxis X,CGFloat tx){
    return X==MKCGAxisX?CGAffineTransformMakeTranslation(tx,0):CGAffineTransformMakeTranslation(0,tx);
}
#pragma mark - CATransform3D
UIKIT_STATIC_INLINE CATransform3D MKCATransform3DMakeTranslation(MKCGAxis X,CGFloat tx){
    return X==MKCGAxisX?CATransform3DMakeTranslation(tx, 0, 0):CATransform3DMakeTranslation(0, tx, 0);
}
UIKIT_STATIC_INLINE CATransform3D MKCATransform3DMakeRotation(MKCGAxis X,CGFloat angle){
    return X==MKCGAxisX?CATransform3DMakeRotation(angle, 1, 0, 0):CATransform3DMakeRotation(angle, 0, 1, 0);
}
UIKIT_STATIC_INLINE CATransform3D MKCATransform3DMakeScale(MKCGAxis X ,CGFloat sx){
    return X==MKCGAxisX?CATransform3DMakeScale(sx, 1, 1):CATransform3DMakeScale(1, sx, 1);
}

//闭区间
struct MKCGRange {
    CGFloat begin;
    CGFloat end;
};
typedef struct CG_BOXABLE MKCGRange MKCGRange;

UIKIT_STATIC_INLINE MKCGRange MKCGRangeMake(CGFloat begin, CGFloat end){
    return (MKCGRange){begin,end};
}
UIKIT_STATIC_INLINE CGFloat MKCGRangeInterpolate(MKCGRange range, CGFloat progress){//插值
    return range.begin * (1.0 - progress) + range.end * progress;
}
UIKIT_STATIC_INLINE BOOL MKCGRangeContainsValue(MKCGRange range, CGFloat v){//是否包含指定值
    return v>=range.begin && v<=range.end;
}
UIKIT_STATIC_INLINE BOOL MKCGRangeIsNull(MKCGRange r){//是否是无效的区域
    return r.end<r.begin;
}
UIKIT_STATIC_INLINE BOOL MKCGRangeIsEmpty(MKCGRange r){//是否是空区间
    return r.end==r.begin;
}
UIKIT_STATIC_INLINE BOOL MKCGRangeIntersectsRange(MKCGRange r1,MKCGRange r2){//两个区间是否相交
    return MKCGRangeContainsValue(r1,r2.end) || MKCGRangeContainsValue(r1, r2.begin)
    ||MKCGRangeContainsValue(r2,r1.end) || MKCGRangeContainsValue(r2, r1.begin)
    ;
}
UIKIT_STATIC_INLINE MKCGRange MKCGRangeUnion(MKCGRange r1,MKCGRange r2){//返回两个区间的并
    return MKCGRangeMake(MIN(r1.begin,r2.begin), MAX(r1.end,r2.end));
}
UIKIT_STATIC_INLINE MKCGRange MKCGRangeIntersection(MKCGRange r1,MKCGRange r2){//返回两个区间的交，没有交集时，返回无效区间
    return MKCGRangeMake(MAX(r1.begin,r2.begin), MIN(r1.end,r2.end));
}
UIKIT_STATIC_INLINE MKCGRange MKCGRectGetRange(CGRect rect,MKCGAxis axis){
    return MKCGRangeMake(MKCGRectGetMin(rect, axis), MKCGRectGetMax(rect, axis));
}
UIKIT_STATIC_INLINE CGFloat MKCGRangeGetMin(MKCGRange r){
    return r.begin;
}
UIKIT_STATIC_INLINE CGFloat MKCGRangeGetMax(MKCGRange r){
    return r.end;
}
UIKIT_STATIC_INLINE CGFloat MKCGRangeGetMid(MKCGRange r){
    return r.begin+(r.end-r.begin)*0.5;
}
UIKIT_STATIC_INLINE CGFloat MKCGRangeGetLength(MKCGRange r){
    return r.end-r.begin;
}

UIKIT_STATIC_INLINE NSComparisonResult MKCGRangeCompareWithValue(MKCGRange r,CGFloat value){
    return MKCGRangeContainsValue(r,value)?NSOrderedSame:(r.end<value?NSOrderedAscending:NSOrderedDescending);
}
UIKIT_STATIC_INLINE NSComparisonResult MKCGRangeCompareWithRange(MKCGRange r1,MKCGRange r2){
    return MKCGRangeIntersectsRange(r1, r2)?NSOrderedSame:(r1.end<r2.begin?NSOrderedAscending:NSOrderedDescending);
//    return MKCGRangeContainsValue(r,value)?NSOrderedSame:(r.end<value?NSOrderedAscending:NSOrderedDescending);
}

UIKIT_STATIC_INLINE NSComparisonResult MKCGRectCompareWithPoint(CGRect rect,CGPoint point,MKCGAxis axis){
    return MKCGRangeCompareWithValue(MKCGRectGetRange(rect, axis), MKCGPointGetValue(point, axis));
}
UIKIT_STATIC_INLINE NSComparisonResult MKCGRectCompareWithCGRect(CGRect r1,CGRect r2,MKCGAxis axis){
    return MKCGRangeCompareWithRange(MKCGRectGetRange(r1,axis), MKCGRectGetRange(r2,axis));
}


UIKIT_STATIC_INLINE UIEdgeInsets MKUIEdgeInsetsMakeSameEdge(CGFloat edge){
    return UIEdgeInsetsMake(edge, edge, edge, edge);
}

NS_ASSUME_NONNULL_END



NS_ASSUME_NONNULL_BEGIN
//插值
UIKIT_STATIC_INLINE CGFloat MKCGFloatInterpolate(CGFloat v1, CGFloat v2, CGFloat progress){
    return v1 * (1.0 - progress) + v2 * progress;
}
UIKIT_STATIC_INLINE CGPoint MKCGPointInterpolate(CGPoint v1, CGPoint v2, CGFloat progress){
    return CGPointMake(MKCGFloatInterpolate(v1.x,v2.x,progress), MKCGFloatInterpolate(v1.y,v2.y,progress));
}
UIKIT_STATIC_INLINE CGVector MKCGVectorInterpolate(CGVector v1, CGVector v2, CGFloat progress){
    return CGVectorMake(MKCGFloatInterpolate(v1.dx,v2.dx,progress), MKCGFloatInterpolate(v1.dy,v2.dy,progress));
}
UIKIT_STATIC_INLINE CGSize MKCGSizeInterpolate(CGSize v1, CGSize v2, CGFloat progress){
    return CGSizeMake(MKCGFloatInterpolate(v1.width,v2.width,progress), MKCGFloatInterpolate(v1.height,v2.height,progress));
}
UIKIT_STATIC_INLINE CGRect MKCGRectInterpolate(CGRect v1, CGRect v2, CGFloat progress){
    return CGRectMake(
        MKCGFloatInterpolate(v1.origin.x,v2.origin.x,progress),
        MKCGFloatInterpolate(v1.origin.y,v2.origin.y,progress),
        MKCGFloatInterpolate(v1.size.width,v2.size.width,progress),
        MKCGFloatInterpolate(v1.size.height,v2.size.height,progress)
    );
}
UIKIT_STATIC_INLINE CGAffineTransform MKCGAffineTransformInterpolate(CGAffineTransform v1, CGAffineTransform v2, CGFloat progress){
    return CGAffineTransformMake(
        MKCGFloatInterpolate(v1.a,v2.a,progress),
        MKCGFloatInterpolate(v1.b,v2.b,progress),
        MKCGFloatInterpolate(v1.c,v2.c,progress),
        MKCGFloatInterpolate(v1.d,v2.d,progress),
        MKCGFloatInterpolate(v1.tx,v2.tx,progress),
        MKCGFloatInterpolate(v1.ty,v2.ty,progress)
    );
}
UIKIT_STATIC_INLINE CATransform3D MKCATransform3DInterpolate(CATransform3D v1, CATransform3D v2, CGFloat progress){
    CATransform3D v = CATransform3DIdentity;
    v.m11 = MKCGFloatInterpolate(v1.m11,v2.m11,progress);
    v.m12 = MKCGFloatInterpolate(v1.m12,v2.m12,progress);
    v.m13 = MKCGFloatInterpolate(v1.m13,v2.m13,progress);
    v.m14 = MKCGFloatInterpolate(v1.m14,v2.m14,progress);
    v.m21 = MKCGFloatInterpolate(v1.m21,v2.m21,progress);
    v.m22 = MKCGFloatInterpolate(v1.m22,v2.m22,progress);
    v.m23 = MKCGFloatInterpolate(v1.m23,v2.m23,progress);
    v.m24 = MKCGFloatInterpolate(v1.m24,v2.m24,progress);
    v.m31 = MKCGFloatInterpolate(v1.m31,v2.m31,progress);
    v.m32 = MKCGFloatInterpolate(v1.m32,v2.m32,progress);
    v.m33 = MKCGFloatInterpolate(v1.m33,v2.m33,progress);
    v.m34 = MKCGFloatInterpolate(v1.m34,v2.m34,progress);
    v.m41 = MKCGFloatInterpolate(v1.m41,v2.m41,progress);
    v.m42 = MKCGFloatInterpolate(v1.m42,v2.m42,progress);
    v.m43 = MKCGFloatInterpolate(v1.m43,v2.m43,progress);
    v.m44 = MKCGFloatInterpolate(v1.m44,v2.m44,progress);
    return v;
}

UIKIT_STATIC_INLINE UIColor *__MKUIColorInterpolate(UIColor *v1, UIColor *v2, CGFloat progress){//插值
    CGFloat r1,g1,b1,a1;[v1 getRed:&r1 green:&g1 blue:&b1 alpha:&a1];
    CGFloat r2,g2,b2,a2;[v2 getRed:&r2 green:&g2 blue:&b2 alpha:&a2];
    CGFloat r = MKCGFloatInterpolate(r1,r2,progress);
    CGFloat g = MKCGFloatInterpolate(g1,g2,progress);
    CGFloat b = MKCGFloatInterpolate(b1,b2,progress);
    CGFloat a = MKCGFloatInterpolate(a1,a2,progress);
    UIColor *v = [UIColor colorWithRed:r green:g blue:b alpha:a];
    return v;
}

UIKIT_STATIC_INLINE UIColor *MKUIColorInterpolate(UIColor *v1, UIColor *v2, CGFloat progress){//插值
    UIColor *v;
    if (@available(iOS 13.0, *)) {
        v = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            UIColor *c1 = [v1 resolvedColorWithTraitCollection:traitCollection];
            UIColor *c2 = [v2 resolvedColorWithTraitCollection:traitCollection];
            return __MKUIColorInterpolate(c1,c2,progress);
        }];
    } else {
        v = __MKUIColorInterpolate(v1,v2,progress);
    }
    return v;
}
NS_ASSUME_NONNULL_END
